<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Pesquisar Certidão de Óbito</h2>
        </ui:define>

        <ui:define name="body">
            <p:panel styleClass="container_24 clearfix">
                <div class="buttonAction" style="float: right">
                    <p:button value="Adicionar" href="criarcertidaoobito.xhtml" icon="ui-icon-plusthick"
                              styleClass="ui-priority-primary"/>
                </div>
                <br/>
            </p:panel>

            <h:form id="certidaoForm" enctype="multipart/form-data">            
                <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />
                <p:panel id="dadosGeraisPanel" styleClass="container_24 clearfix">
                    <h2>Filtros</h2>

                    <p:outputLabel value="Número:" styleClass="grid_3" for="numeroInputText" />
                    <p:inputText id="numeroInputText" styleClass="grid_8"
                                 value="#{managerPesquisarCertidaoObito.certidaoPesquisar.numero}" />

                    <p:outputLabel value="Data:" styleClass="grid_4" for="dataCalendar" />
                    <p:calendar id="dataCalendar" value="#{managerPesquisarCertidaoObito.certidaoPesquisar.dataCertidao}"
                                showOn="both" locale="pt" yearRange="1900:2100" 
                                navigator="true" pattern="dd/MM/yyyy" styleClass="grid_9" />
                    <div class="clear" />

                    <p:outputLabel value="Causa:" styleClass="grid_3 estabelecimentoLabel" for="causaInputText" />
                    <p:inputText id="causaInputText" styleClass="grid_20"
                                 value="#{managerPesquisarCertidaoObito.certidaoPesquisar.causa}" />

                    <div class="clear"/>
                    <br/>

                    <h2>Falecido</h2>

                    <p:outputLabel value="CPF:" styleClass="grid_3"/>
                    <p:inputMask value="#{managerPesquisarCertidaoObito.pessoaPesquisar.cpf}" 
                                 styleClass="grid_8" mask='999.999.999-99'
                                 autocomplete="false" />

                    <p:outputLabel value="RG:" styleClass="grid_4" for="rgInputText"/> 
                    <div class="grid_9">
                        <p:inputText id="rgInputText" style="width: 90%"
                                     value="#{managerPesquisarCertidaoObito.pessoaPesquisar.rg}"/>
                    </div>
                    <div class="clear"/>

                    <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeInputText"/>
                    <p:inputText id="nomeInputText" 
                                 value="#{managerPesquisarCertidaoObito.pessoaPesquisar.nome}" 
                                 styleClass="grid_20"/>
                    <div class="clear"/>
                    <div class="clear"/>

                    <br/>
                    <div class="buttonAction">
                        <p:commandButton value="Pesquisar" styleClass="ui-priority-primary"
                                         actionListener="#{managerPesquisarCertidaoObito.pesquisar()}"
                                         update=":certidaoForm:declaracoesPanel, :certidaoForm:portariasTable"
                                         id="pesquisarCommandButton" icon="ui-icon-search"/>
                    </div>
                </p:panel> 

                <p:panel id="declaracoesPanel" styleClass="container_24 clearfix">
                    <p:dataTable id="portariasTable" var="item" value="#{managerPesquisarCertidaoObito.certidoes}" 
                                 styleClass="grid_24" emptyMessage="Nenhum registro">  
                        <f:facet name="header">
                            Declarações
                        </f:facet>

                        <p:column headerText="Ação" width="50">
                            <p:button title="Visualizar"
                                      href="visualizarcertidaoobito.xhtml?vCertidao=#{item.id}"
                                      icon="ui-icon-zoomin"/>
                            <p:commandButton update="@form, :certidaoForm:declaracoesPanel" title="Excluir"
                                             oncomplete="dlg.show()"
                                             icon="ui-icon-trash" >
                                <f:setPropertyActionListener target="#{managerPesquisarCertidaoObito.certidaoDeletar}" value="#{item}" />
                            </p:commandButton>
                        </p:column>

                        <p:column headerText="Número" width="130">  
                            #{item.numero}
                        </p:column>

                        <p:column headerText="Falecido">  
                            #{item.pessoa.nome}
                        </p:column> 

                        <p:column headerText="Data" width="100">  
                            <h:outputLabel value="#{item.dataCertidao}" >
                                <f:convertDateTime pattern="dd/MM/yyyy" locale="pt-br" />
                            </h:outputLabel>
                        </p:column>

                    </p:dataTable>

                    <div class="buttonAction">
                        <p:button value="Cancelar" icon="ui-icon-circle-close"
                                  href="indexcertidaoobito.xhtml" />
                    </div>

                </p:panel>

                <p:dialog id="modalDialog" header="Confirmação de remoção" 
                          widgetVar="dlg" height="80"
                          closable="false" resizable="false">

                    <h:outputText value="Tem certeza que deseja remover esta certidão?" />
                    <div class="buttonAction">
                        <p:commandButton value="Sim"
                                         actionListener="#{managerPesquisarCertidaoObito.deletar()}"
                                         update="@form, :certidaoForm:declaracoesPanel"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="Não" icon="ui-icon-close"
                                         oncomplete="dlg.hide()" />

                    </div>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>


